package com.qdu.reducer;

import com.qdu.bean.EverydayBean;
import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;


public class WorkDayReducer extends Reducer<Text, EverydayBean, Text, EverydayBean> {


    @Override
    protected void reduce(Text key, Iterable<EverydayBean> values, Context context) throws IOException, InterruptedException {
        int sum=0;
        int casual=0;
        int registered=0;
        int count=0;

        for (EverydayBean s :
                values) {
            sum+=s.getCount();
            casual+=s.getCasual();
            registered+=s.getRegistered();
            count++;
        }
        sum=sum/count*24;
        casual=casual/count*24;
        registered=registered/count*24;
        context.write(new Text(key.toString()),new EverydayBean(sum,casual,registered));
    }
}


